﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AI_BOTS
{
	public static class Bots
	{
		public static void LogicalBot(PlanetWars pw)
		{
			//     attack the nearest/weakest average planet
			double multiplier = .75;
			foreach(Planet p in PlanetFactory.FetchPlanetsByStrength(pw, PlanetFactory.PLANET_TYPES.MINE, true, null))
			{
				List<Planet> planets = PlanetFactory.FetchBestAttackOrder(pw, p.PlanetID, PlanetFactory.PLANET_TYPES.BOTH, 1);
				foreach(Planet attackDest in planets)
				{
					int fleetsToSend = Convert.ToInt16(Math.Floor(p.NumShips * multiplier));
					if(fleetsToSend <= 0)
						break;

					// dont issue atatck if incomming fleets will take the planet
					if(p.WillAttackingLeaveVulnerable(attackDest, fleetsToSend))
					{
						p.SendFleetsStandard(attackDest, fleetsToSend);						
					}
				}
			}
		}

		public static void TakeClosestBot(PlanetWars pw)
		{
			try
			{
				foreach(Planet p in pw.MyPlanets())
				{
					int maxPlanetsToTake = 4;
					List<Planet> weakPlanets = p.ClosestPlanets(PlanetFactory.PLANET_TYPES.NUERTAL, maxPlanetsToTake);
					if(weakPlanets.Count > 0)
					{
						for(int i = 0;i <= maxPlanetsToTake - 1;i++)
						{
							if(p.NumShips >= 25)
								p.SendEnoughShipsToTake(weakPlanets[i]);
						}

					}
				}
			}
			catch(Exception ex)
			{
				pw.FinishTurn();
			}
		}

		public static void RageBot(PlanetWars pw)
		{
			if(pw.MyFleets().Count > 0)
				return;

			// act like an asshole
			foreach(Planet myPlanet in PlanetFactory.FetchPlanetsByStrength(pw, PlanetFactory.PLANET_TYPES.MINE, true, null))
			{
				List<Planet> enemyPlanets = PlanetFactory.FetchPlanetsByStrength(pw, PlanetFactory.PLANET_TYPES.ENEMY, true, 1);
				myPlanet.SendFleetsRage(enemyPlanets[0]);
			}
		}
	}
}


